package com.actionpals.collections
{
	/**
	 * Array based iterator.
	 * 
	 * @author Mark Walters
	 */
	public class ArrayIterator implements IIterator
	{
		private var collection:Array;
		private var index:uint;
		
		/**
		 * Constructor.
		 */
		public function ArrayIterator( collection:Array )
		{
			this.collection = collection;
			index = 0;
		}
		
		/**
		 *The current cursor position.
		 */
		public function get cursor():uint
		{
			return index;
		}
		
		/**
		 * private
		 */
		public function set cursor( value:uint ):void
		{
			index = value;
		}
		
		/**
		 * Checks to see if there is a previous item in the collection.
		 * 
		 * @return The collection has another item or not.
		 */
		public function hasPrevious():Boolean
		{
			return index > 0;
		}
		
		/**
		 * Checks to see if there is a next item in the collection.
		 * 
		 * @return The collection has another item or not.
		 */
		public function hasNext():Boolean
		{
			return index < collection.length;
		}
		
		/**
		 * Moves the cursor to the previous item in the collection and returns that item.
		 * 
		 * @return The previous item in the collection.
		 */
		public function previous():Object
		{
			return collection[ index-- ];
		}
		
		/**
		 * Moves the cursor to the next item in the collection and returns that item.
		 * 
		 * @return The next item in the collection.
		 */
		public function next():Object
		{
			return collection[ index++ ];
		}
		
		/**
		 * Resets the cursor back to the first item in the collection.
		 */
		public function reset():void
		{
			index = 0;
		}
		
	}
}